home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / gadgets.lzh / Gadgets / Example1.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  143 lines

  1. /* Example1                                                            */
  2. /* This program will open a normal window which is connected to the    */
  3. /* Workbench Screen. The window will use all System Gadgets, and will  */
  4. /* close first when the user has selected the System gadget Close      */
  5. /* window. (Same as Example3 in chapter 2 WINDOWS, except that we have */
  6. /* added an IDCMP check on the Close window gadget.)                   */
  7.  
  8. /* Extra information:                                                    */
  9. /* This program will quit first when the user has selected the Close     */
  10. /* window gadget. To tell Intuition that we want the System gadget Close */
  11. /* window to send us a message when the user selects it, we only need to */
  12. /* set the CLOSEWINDOW flag in the IDCMPFlags field.                     */
  13.  
  14.  
  15.  
  16. #include <intuition/intuition.h>
  17.  
  18.  
  19.  
  20. struct IntuitionBase *IntuitionBase;
  21.  
  22.  
  23.  
  24. /* Declare a pointer to a Window structure: */ 
  25. struct Window *my_window;
  26.  
  27. /* Declare and initialize your NewWindow structure: */
  28. struct NewWindow my_new_window=
  29. {
  30.   50,            /* LeftEdge    x position of the window. */
  31.   25,            /* TopEdge     y positio of the window. */
  32.   200,           /* Width       200 pixels wide. */
  33.   100,           /* Height      100 lines high. */
  34.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  35.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  36.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  37.                  /*             user has selected the Close window gad. */
  38.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  39.   WINDOWCLOSE|   /*             Close Gadget. */
  40.   WINDOWDRAG|    /*             Drag gadget. */
  41.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  42.   WINDOWSIZING|  /*             Sizing Gadget. */
  43.   ACTIVATE,      /*             The window should be Active when opened. */
  44.   NULL,          /* FirstGadget No Custom gadgets. */
  45.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  46.   "CLOSE ME",    /* Title       Title of the window. */
  47.   NULL,          /* Screen      Connected to the Workbench Screen. */
  48.   NULL,          /* BitMap      No Custom BitMap. */
  49.   80,            /* MinWidth    We will not allow the window to become */
  50.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  51.   300,           /* MaxWidth    than 300 x 200. */
  52.   200,           /* MaxHeight */
  53.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  54. };
  55.  
  56.  
  57.  
  58. main()
  59. {
  60.   /* Boolean variable used for the while loop: */
  61.   BOOL close_me;
  62.  
  63.   /* Declare a variable in which we will store the IDCMP flag: */
  64.   ULONG class;
  65.   
  66.   /* Declare a pointer to an IntuiMessage structure: */
  67.   struct IntuiMessage *my_message;
  68.  
  69.  
  70.  
  71.   /* Before we can use Intuition we need to open the Intuition Library: */
  72.   IntuitionBase = (struct IntuitionBase *)
  73.     OpenLibrary( "intuition.library", 0 );
  74.   
  75.   if( IntuitionBase == NULL )
  76.     exit(); /* Could NOT open the Intuition Library! */
  77.  
  78.  
  79.  
  80.   /* We will now try to open the window: */
  81.   my_window = (struct Window *) OpenWindow( &my_new_window );
  82.   
  83.   /* Have we opened the window succesfully? */
  84.   if(my_window == NULL)
  85.   {
  86.     /* Could NOT open the Window! */
  87.     
  88.     /* Close the Intuition Library since we have opened it: */
  89.     CloseLibrary( IntuitionBase );
  90.  
  91.     exit();  
  92.   }
  93.  
  94.  
  95.  
  96.   /* We have opened the window, and everything seems to be OK. */
  97.  
  98.  
  99.  
  100.   close_me = FALSE;
  101.  
  102.   /* Stay in the while loop until the user has selected the Close window */
  103.   /* gadget: */
  104.   while( close_me == FALSE )
  105.   {
  106.     /* Wait until we have recieved a message: */
  107.     Wait( 1 << my_window->UserPort->mp_SigBit );
  108.  
  109.     /* Collect the message: */
  110.     my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort );
  111.     /* Ahhh, these paranoid compilers... */
  112.  
  113.     /* Have we collected the message sucessfully? */
  114.     if(my_message)
  115.     {
  116.       /* After we have collected the message we can read it, and save any */
  117.       /* important values which we maybe want to check later: */
  118.       class = my_message->Class;
  119.  
  120.       /* After we have read it we reply as fast as possible: */
  121.       /* REMEMBER! Do never try to read a message after you have replied! */
  122.       /* Some other process has maybe changed it. */
  123.       ReplyMsg( my_message );
  124.  
  125.       /* Check which IDCMP flag was sent: */
  126.       if( class == CLOSEWINDOW )
  127.         close_me=TRUE; /* The user selected the Close window gadget! */  
  128.     }
  129.   }
  130.  
  131.  
  132.  
  133.   /* We should always close the windows we have opened before we leave: */
  134.   CloseWindow( my_window );
  135.  
  136.  
  137.  
  138.   /* Close the Intuition Library since we have opened it: */
  139.   CloseLibrary( IntuitionBase );
  140.   
  141.   /* THE END */
  142. }
  143.